package com.crm.sys.tab;

import java.io.IOException;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.servlet.tags.RequestContextAwareTag;

import com.crm.sys.model.CityAndProvinceDic;
import com.crm.util.Constants;

public class StringTag extends RequestContextAwareTag  {
	/**
	 * 
	 */
	private static final long serialVersionUID = -7671375971979063913L;
	private String value; 
	private Integer minLength;
	private Integer maxLength=10;
	private String ext="..."; //未完全展示内容符号
	
      
 
	public void setMinLength(Integer minLength) {
		this.minLength = minLength;
	}

	public void setMaxLength(Integer maxLength) {
		this.maxLength = maxLength;
	}

	public void setExt(String ext) {
		this.ext = ext;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public StringTag(){  
       // System.out.println("MyTag构造方法：一个myTag类的对象被构建了....");  
    }  
      
    /*public int doStartTag() {  
       
    } */ 
    public int doAfterBody() throws JspException{  
       // System.out.println("处理标签体（after body）....");  
        return SKIP_BODY;  
    }  
    public int doEndTag() throws JspException{  
      //  System.out.println("对象正在处理结束标记.....");  
        return EVAL_PAGE;  
    }

	@Override
	protected int doStartTagInternal() throws Exception {
		 JspWriter out = this.pageContext.getOut(); 
	        try {  
	        	  try{
	        		    if(StringUtils.isNotEmpty(value)&&value.length()>maxLength){
	        		    	out.print(value.substring(0,maxLength)+ext);
	        		    }else{
	        		    	out.print(value);
	        		    }
			       	}catch(Exception e1){
			       	 out.print("");  
			       	}
	           
	        } catch (IOException e) {  
	            //e.printStackTrace();  
	        }  
	          
	        //System.out.println("对象正在处理开始标记.....");  
	        return EVAL_BODY_INCLUDE;  
	}  
}
